package com.oa.listenter;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.oa.bean.Privilege;
import com.oa.dao.IndexDao;
import com.oa.service.SystemService;

import com.oa.service.impl.SystemServiceImpl;


public class InitListener implements ServletContextListener{

/*	@Resource
	private SystemService systemServiceImpl;*/
	@Override
	public void contextDestroyed(ServletContextEvent sce1) {
		System.out.println("权限数据结束");
	}

	@Override
	public void contextInitialized(ServletContextEvent sce) {
	
		System.out.println("ooooooo");
		//1.获取spring容器
		WebApplicationContext applicationContext = WebApplicationContextUtils.getWebApplicationContext(sce.getServletContext());
		//2.从spring容器中获取SystemManageController
		SystemService service=(SystemService)applicationContext.getBean("systemServiceImpl");
		//3.查询数据
		List<Privilege> findAllPrivilegeUrl = service.findAllPrivilegeUrl();
		sce.getServletContext().setAttribute("findAllPrivilegeUrl",findAllPrivilegeUrl);
		System.out.println("权限数据已经放入application作用域了");
	}

}
